package com.aaa.controller;

import com.aaa.service.L_ZHSHService;
import com.aaa.util.EmpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/zhsh")
public class L_ZHSHController {
    @Autowired
    private L_ZHSHService service;

    @RequestMapping("/aa")
    public String hello(){
        return  "Registrationaudit/Registrationaudit";
    }

    @RequestMapping("/list")
    @ResponseBody
    public Object list(@RequestBody Map map){
            Integer manage=EmpUtil.getEmp().getDeptid();
            map.put("manage",manage);//有等级
            if (manage==1){
                List<Map> list=service.getAll(map);
                System.out.println(map.get("name"));
                Integer total=service.getCount(map);
                Map maps=new HashMap();
                maps.put("data",list);
                maps.put("total",total);
                return maps;
            }else {

                List<Map> list=service.getAll1(map);
                System.out.println(map.get("name"));
                Integer total=service.getCount(map);
                Map maps=new HashMap();
                maps.put("data",list);
                maps.put("total",total);
                return maps;
            }

    }
        //获取登陆人的所属文明办
        @RequestMapping("/manage")
        @ResponseBody
            public  Object manage(){
            return EmpUtil.getEmp().getDeptid();
        }

    //查看数据
    @RequestMapping("/chakan/{id}")
    @ResponseBody
    public Object chakan(@PathVariable Integer id){
        Map map=new HashMap();
        map.put("data",service.chakan(id));
        System.out.println(id+"aaaaaaaa");
        return map;
    }

    //市级单位审核
    @RequestMapping("/shenhe")
    @ResponseBody
    public String shenhe(@RequestBody Map map){
        Date date=new Date();
        SimpleDateFormat aa=new SimpleDateFormat("yyyy-MM-dd");
        String time=aa.format(date);
        String user= EmpUtil.getEmp().getUsername();
        map.put("SHtime",time);
        map.put("SHuser",user);
        service.shenhe(map);
        return  "redirect:../zhsh/aa";
    }

    //省级单位审核
    @RequestMapping("/shenhe1")
    @ResponseBody
    public String shenhe1(@RequestBody Map map){
        Date date=new Date();
        SimpleDateFormat aa=new SimpleDateFormat("yyyy-MM-dd");
        String time=aa.format(date);
        String user= EmpUtil.getEmp().getUsername();
        map.put("SHtime",time);
        map.put("SHuser",user);
        service.shenhe1(map);
        return  "redirect:../zhsh/aa";
    }

    //审核前的审核级别判断
    @RequestMapping("/pan")
    @ResponseBody
    public Object pan(@RequestBody Map map){
        System.out.println(map);
        Object manage=map.get("manage");
        System.out.println(manage);
        Integer i=EmpUtil.getEmp().getDeptid();//当前登录人的权限等级
        System.out.println(i+"       审核人等级");
        int state=service.getstate(map);//获取当前单位的审核状态
        System.out.println(state+"             审核状态");
        if (i==1){//说明权限为省
            if (state==1){//市级已经审核
                return "1";
            }else if (state==0){
                return "0";//省级无法审核
            }
        }else {
            if(state==0){//市级审核
                //修改审核状态  新增审核人  审核时间
                return  "2";//市级可审核
            }else if(state==1){
                return "3";//市级不能审核，由省级审核
            }
        }
        return "4";
    }

    //基本信息显示
    @RequestMapping("/Ess")
    @ResponseBody
       public Map Ess(){
        String  name=EmpUtil.getMessage().getName();
        Map list=service.Ess(name);
        return list;
    }


}
